//
//  orderDetial.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/5/22.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "orderDetial.h"
#import "orderListDetialModel.h"
@interface orderDetial () <UITableViewDelegate, UITableViewDataSource> {
    orderListDetialModel *detialModel;
}
@property (nonatomic, copy) NSDictionary *dic;
@property (nonatomic, strong) UITableView *listView;
@end

@implementation orderDetial

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - StatusBarAndNavigationBarHeight - TabbarSafeBottomMargin);
    self.listView = [[UITableView alloc]initWithFrame:frame];
    if (@available(iOS 11.0, *)) {
        self.listView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        //        if (iPhoneX) {
        //            self.detialView.contentInset = UIEdgeInsetsMake(0, 0, 88, 0);
        //        }else {
        //            self.detialView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
        //        }
        //        self.detialView.scrollIndicatorInsets = self.detialView.contentInset;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.listView.delegate = self;
    self.listView.dataSource = self;
    self.listView.tableFooterView = [UIView new];
    [self.view addSubview:self.listView];
    [self detialRequest];
}

#pragma mark --- uitableViewDelegate and dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return detialModel ? self.dic.count : 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (!detialModel) {
        return nil;
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oederDetial"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"oederDetial"];
        cell.selectionStyle = UITableViewCellAccessoryNone;
        cell.textLabel.font = [UIFont customFontOfSize:13];
        cell.detailTextLabel.font = [UIFont  customFontOfSize:13];
    }
//    NSString *oid = detialModel.oid;
//    NSDictionary *dataDic = @{@"订单号":detialModel.oid, @"学员姓名":@"网易翔", @"手机号码":@"15783763947", @"身份证号":@"934563486593487655656", @"驾校名称":@"人民驾校", @"付款金额":@"6000.00元", @"分期详情":@"分3期，每期10000元", @"付款时间":@"1028-08-14 19:10"};
    cell.textLabel.text = [self.dic.allKeys objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [self.dic.allValues objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
    grayView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    return grayView;
}
#pragma mark --- 请求详情页数据
- (void)detialRequest {
    NSDictionary *dic = @{
                          @"token":USERTOKEN
                          };
    __weak typeof(self) weakSelf = self;
    NSString *url = [NSString stringWithFormat:@"%@%@", [[apiManger shareApiManger] orderListDetial], self.Id];
    [networkManger PostHttpDataWithUrlStr:url Dic:dic SuccessBlock:^(id responseObject) {
        if ([responseObject[@"rcd"] isEqualToString:R0001]) {
            detialModel = [orderListDetialModel mj_objectWithKeyValues:responseObject[@"data"]];
            weakSelf.dic;
            [weakSelf.listView reloadData];
        }else {
            [MBProgressHUD gk_toastShowMessage:responseObject[@"rmg"]];
        }
    } FailureBlock:^(id error) {
        [MBProgressHUD gk_toastShowMessage:@"请求失败"];
    }];
}
#pragma mark --- getter
- (NSDictionary *)dic {
    if (!_dic) {
        NSString *date = [NSString ConvertStrToTime:detialModel.createDate];
        NSString *fenQi = [NSString stringWithFormat:@"分%@期，每期%@元", detialModel.divides, detialModel.repayMoney];
        _dic = @{@"订单号":detialModel.oid, @"学员姓名":detialModel.realName == nil ? @"" : detialModel.realName, @"手机号码":detialModel.phone, @"身份证号":detialModel.idCard == nil ? @"" : detialModel.idCard, @"驾校名称":detialModel.name, @"付款金额":detialModel.price, @"分期详情":fenQi, @"付款时间":date};
    }
    return _dic;
}
- (void)dealloc {
    
}

@end
